package com.anmong.cloud.cloudadmin.common.config;

import com.anmong.cloud.cloudadmin.common.filter.RepeatedlyReadFilter;
import jakarta.servlet.Filter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class FilterConfig {

    @Bean
    public FilterRegistrationBean someFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(repeatedlyReadFilter());
        //设置url过滤器 匹配的url
        registration.addUrlPatterns("/*");
        //名称
        registration.setName("repeatedlyReadFilter");
        //多个filter 设置顺序 默认越小 代表调用顺序越靠前
        registration.setOrder(1);
        return registration;
    }

    /**
     * 定义filter对应的bean
     *
     * @return Filter
     */
    @Bean
    public Filter repeatedlyReadFilter() {
        return new RepeatedlyReadFilter();
    }
}
